<template>
  <el-drawer
    :title="title"
    :visible.sync="drawer"
    :direction="direction"
    :before-close="handleClose"
  >
    <div class="drawer-content">
      <el-input
        type="textarea"
        :rows="3"
        placeholder="请输入内容"
        v-model="content"
        maxlength="150"
        show-word-limit
      >
      </el-input>
      <div class="bottom-button">
        <el-button round @click="clearContent">清空</el-button>
        <el-button type="primary" round @click="commitReply">提交</el-button>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  props: ["artcleId", "userId", "userName"], //文章id，接收者id，接收者用户名
  created() {},
  data() {
    return {
      title: `回复 ${this.userName}`,
      drawer: false,
      direction: "btt", //从下往上
      content: "", //回复内容
    };
  },
  methods: {
    //关闭回复抽屉
    handleClose(done) {
      this.$confirm("是否取消回复？")
        .then((_) => {
          this.content = "";
          done();
        })
        .catch((_) => {});
    },
    //清空评论
    clearContent() {
      this.content = "";
    },
    //提交评论
    commitReply() {
      //当前用户id
      let id = localStorage.getItem("userId");
      this.$request.postHttp({
        url: "/reply/addReply",
        data: {
          articleid: this.artcleId,
          userid: id,
          receiveid: this.userId, //接收者id
          createtime: new Date(),
          replycontent: this.content,
          likecount: 0,
        },
        success: (data) => {
          this.drawer = false;
          this.$emit("getReplyListByArticleId");
        },
        error: (error) => {},
      });
    },
  },
};
</script>

<style scoped>
.drawer-content {
  display: flex;
  flex-direction: column;
}

.bottom-button {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end; /* 将子元素在横轴上放置在末尾（右侧） */
  gap: 10px; /* 可以添加适当的间距 */
}
</style>